voicemeeter\interface\parameters/
eq.rs

1//! Common structs for EQ
2use super::*;
3
4enum Mode {
5    Strip,
6    Bus,
7}
8
9impl std::fmt::Display for Mode {
10    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11        match self {
12            Mode::Strip => f.write_str(STRIP),
13            Mode::Bus => f.write_str(BUS),
14        }
15    }
16}
17
18/// Parameter for EQ on a specific channel and input/output (bus/strip)
19pub struct EqChannelParameter<'a> {
20    remote: &'a VoicemeeterRemote,
21    mode: Mode,
22    index: ZIndex,
23    channel: usize,
24}
25
26impl<'a> EqChannelParameter<'a> {
27    pub(crate) fn new_bus(remote: &'a VoicemeeterRemote, index: ZIndex, channel: usize) -> Self {
28        Self {
29            remote,
30            mode: Mode::Bus,
31            index,
32            channel,
33        }
34    }
35
36    pub(crate) fn new_strip(remote: &'a VoicemeeterRemote, index: ZIndex, channel: usize) -> Self {
37        Self {
38            remote,
39            mode: Mode::Strip,
40            index,
41            channel,
42        }
43    }
44    pub(crate) fn name(&self) -> impl std::fmt::Display + '_ {
45        struct N<'s>(&'s Mode, &'s ZIndex, &'s usize);
46        impl std::fmt::Display for N<'_> {
47            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48                write!(f, "{}[{}].EQ.channel[{}]", self.0, self.1, self.2)
49            }
50        }
51        N(&self.mode, &self.index, &self.channel)
52    }
53    /// Get the identifier for a parameter on this equalizer: `Bus[i].EQ.channel[ch].cell[c].{dot}`
54    pub fn param(&self, cell: usize, dot: impl ToString) -> Cow<'static, ParameterNameRef> {
55        Cow::Owned(format!("{}.cell[{}].{}", self.name(), cell, dot.to_string()).into())
56    }
57    /// Turn EQ cell on or off
58    pub fn on(&self, cell: usize) -> BoolParameter<'_> {
59        BoolParameter::new(self.param(cell, "on"), self.remote)
60    }
61    /// Type of EQ filter.
62    pub fn type_(&self, cell: usize) -> IntParameter<'_> {
63        // TODO: Enum Parameter
64        IntParameter::new(self.param(cell, "type"), self.remote, 0..=6)
65    }
66    /// Frequency of the EQ filter.
67    pub fn f(&self, cell: usize) -> FloatParameter<'_> {
68        // TODO: Enum Parameter
69        FloatParameter::new(self.param(cell, "f"), self.remote, 20.0..=20_000.0)
70    }
71    /// Gain of the EQ filter.
72    pub fn gain(&self, cell: usize) -> FloatParameter<'_> {
73        // TODO: Enum Parameter
74        // NOTE: Docs say -12 to 12, but interface allows -36 to 18
75        FloatParameter::new(self.param(cell, "gain"), self.remote, -36.0..=18.0)
76    }
77    /// Quality of the EQ filter.
78    pub fn q(&self, cell: usize) -> IntParameter<'_> {
79        // TODO: Enum Parameter
80        IntParameter::new(self.param(cell, "q"), self.remote, 1..=100)
81    }
82}